package com.Q08;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @version v1.0.0
 * 创建时间：2022/8/8 11:32
 */
public class Q08_13 {
    public int pileBox(int[][] box) {
        if (box.length==0) return 0;
        // 排序后dp
        Arrays.sort(box, Comparator.comparingInt(a -> a[0]));
        // dp[i] 从i位置当底座的最大高度
        // dp[i] = dp[j] + box[i][2](底)
        int[] dp = new int[box.length];
        for (int i = 0; i < box.length; i++) {
            dp[i] = box[i][2];
        }
        int res = 0;
        for (int i = 0; i < box.length; i++) {
            for (int j = 0; j < i; j++) {
                if (box[j][0]<box[i][0] && box[j][1]<box[i][1] && box[j][2]<box[i][2]){
                    dp[i] = Math.max(dp[i],dp[j] + box[i][2]);
                }
            }
            res = Math.max(res,dp[i]);
        }
        return res;
    }

    public static void main(String[] args) {
        new Q08_13().pileBox(new int[][]{{2, 6, 7}, {3, 4, 5}, {1, 1, 1}, {2, 3, 4}});
    }
}
